package weaver.interfaces.expense.action.gzc.th;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.util.ExpenseCompare;
import weaver.interfaces.util.ExpenseCompareUtil;
import weaver.interfaces.util.ExpenseInfoUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
/**
 * 
 * @ClassName: QYSBGZ_TH_ExpenseAction 
 * @Description:  试剂耗材购置申请表费用预算退回
 * @author xiyufei
 * @date 2017-3-20 上午11:19:21 
 *
 */
public class SJHCGZSQ_TH_ExpenseAction  extends BaseBean{

 
	public void execute(String workflowid,String requestid) {  
			writeLog("进入SJHCGZSQ_TH_ExpenseAction-----------"+requestid);
			RecordSet rs = new RecordSet(); 
			rs.executeSql("select formid from workflow_base where id = " + workflowid);
			rs.next();
			String formid = rs.getString("formid");
			String formtable = "formtable_main_" + formid.replaceAll("-", "");
			 
			String ccode = "";
			double amount = 0;
			String cexpenseitemcode = "";
			String citemcode = "";
			String ly = "";
			String iyear = "";
 
			rs.execute("select a.id,b.ks,a.zcxm,a.je,b.zj,b.sqrq,b.kth1 from "+formtable+"_dt1 a , "+formtable+" b where a.mainid=b.id and  b.requestid="+requestid);
			while(rs.next()){ 
				ExpenseInfoUtil expenseInfoUtil = new ExpenseInfoUtil();
				ccode =  expenseInfoUtil.getKsbm(Util.null2String(rs.getString("ks"))); 
				amount =  Util.getDoubleValue(rs.getString("je"),0); 
				cexpenseitemcode=  Util.null2String(rs.getString("zcxm"));  
				String kth =  Util.null2String(rs.getString("kth1"));  
				ly =  Util.null2String(rs.getString("zj"));  
				iyear =  Util.null2String(rs.getString("sqrq")).substring(0,4); 
				String iskt = "0";
				if("0".equals(ly)||"6".equals(ly)){//资金来源为课题或者临床试验经费时 课题号+项目支出
					iskt ="1";
				}
				if("1".equals(ly)){//财政拨款 课题号
					iskt ="1";
				}
				boolean bl =  expenseInfoUtil.releaseExpense(workflowid, ccode, cexpenseitemcode, citemcode, kth, amount, iyear,iskt);
 
			}
			
	 
	}

}
